package binaryTree;

public class CLass572 {

        public boolean isSubtree(TreeNode root, TreeNode subRoot) {
            if(subRoot == null){
                return true;
            }
            if(root == null){
                return false;
            }
            return isSametree(root,subRoot)||isSubtree(root.left,subRoot)||isSubtree(root.right,subRoot);
        }



        public boolean isSametree(TreeNode root,TreeNode subRoot){
            if(root == null &&subRoot == null){
                return true;
            }
            if(root == null || subRoot == null){
                return false;
            }
            if(root.val != subRoot.val){
                return false;
            }
            return isSametree(root.right,subRoot.right)&&isSametree(root.left,subRoot.left);
        }






}
